/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */
var merge = function (nums1, m, nums2, n) {
  let left = 0, right = 0, arr = nums1.slice(0, m),sorted=[]
  for (let i = 0; i < m + n; i++) {
    if(right==n){
      sorted.push(...arr.slice(left))
      break
    }
    if(nums2[right]<arr[left]){
      sorted[i]=nums2[right]
      right++
    }else {
      if(left==m){
        sorted.push(...nums2.slice(right))
        break
      }
      sorted[i]=arr[left]
      left++
    }
  }
  for (let i = 0; i != m + n; ++i) {
    nums1[i] = sorted[i];
}
};

merge([1,2,3,0,0,0],3,[2,5,6],3)